#!/usr/bin/perl -w
use strict;
use DBI;
use LWP::Simple;

# update down set status=0,head=null,url=concat('http://archive.ubuntu.com/ubuntu/',right(url,length(url)-length('http://archive.ubuntu.com/ubuntu/ubuntu/'))) where url regexp '/ubuntu/ubuntu';

our $h=DBI->connect('DBI:mysql:database=Down','root') || die $DBI::errstr;
my $pr=$h->prepare("select id,url from down where status=0 and url regexp '^http://archive.ubuntu.com/ubuntu/'");
my $cancel=$h->prepare(qq/update down set status=2 where status=0 and id=?/);

$pr->execute() or die $DBI::errstr;
while (my ($id,$url)=$pr->fetchrow_array())
{
$url=~s{archive.ubuntu.com/ubuntu}{cdit/ubuntu-nc};
($_)=(head($url))[2];
$cancel->execute($id),print "Got:$url:'$_'\n" if $_;
#print "TEST:$url\n";
}

#$h->do(qq/update down set status=2 where status=0 and id in ($_)/);
#$h->disconnect();
